import path from 'path'
import {defineConfig} from 'vite'
import {getBuild, getPlugins} from './build/config'
import {globalVar} from './build/env/globalVar'

// https://vitejs.dev/config/
export default defineConfig(({command, mode}) => {
    const env = globalVar(command, mode)
    return {
        resolve: {
            // 配置路径别名
            alias: {
                '@': path.resolve(__dirname, './src'),
            },
        },
        plugins: getPlugins(env),
        server: {
            host: '0.0.0.0',
            open: false,
            https: false,
            proxy: {
                '/prod-api': {
                    target: 'http://192.168.1.142:18089',
                    changeOrigin: true,
                    secure: false,
                    ws: true,
                    rewrite: (path) => {
                        console.log('Rewriting path:', path);
                        return path.replace(/^\/prod-api/, '');
                    }
                }
            }
        },
        build: getBuild(env)
    }
})
